package com.mingben.betplatform.thread;

import com.mingben.betplatform.api.baoge3.Baoge3Api;
import com.mingben.betplatform.util.StringUtils;
import com.mingben.betplatform.util.ThreadUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WinStopConditionThread extends Thread{

    private Logger logger = LoggerFactory.getLogger(WinStopConditionThread.class);
    private Baoge3Api api;
    private double winStopMoney;

    /**
     *
     * @param api
     * @param winStopMoney 止赢金额
     */
    public WinStopConditionThread(Baoge3Api api , double winStopMoney){
        this.api = api;
        this.winStopMoney = winStopMoney;
    }

    @Override
    public void run() {

        while (true){
            ThreadUtil.sleep10s();

            String balanceStr = api.balance();
            if(StringUtils.isEmpty(balanceStr)){
                continue;
            }
            if(winStopMoney > Double.valueOf(balanceStr)){
                logger.info(" zhiying tiaojian  wei manzu ,,zhiying jine{} , dangqian jine {}" , winStopMoney , balanceStr);
            }else{
                logger.info(" zhiying tiaojian  yi manzu ,,zhiying jine{} , dangqian jine {}" , winStopMoney , balanceStr);
                System.exit(0);
            }

        }
    }
}
